﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HouseManager.BLL;
using HouseManger.Model;

namespace HouseManager
{
    public partial class Add : System.Web.UI.Page
    {
        MangerBLL MangerBLL = new MangerBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //调用方法给房屋类型下拉框绑定数据源
                drType.DataSource = MangerBLL.GetHouseType();
                drType.DataValueField = "Id";
                drType.DataTextField = "TName";
                drType.DataBind();
            }
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            HouseInfo Info = new HouseInfo()
            {
                Name = txtName.Text,
                Area = Convert.ToDecimal(txtArea.Text),
                Price = Convert.ToDecimal(txtPrice.Text),
                FloorCount = Convert.ToInt32(txtFloorCount.Text),
                Floot = Convert.ToInt32(txtFloor.Text),
                State = rState.SelectedIndex,
                Years = Convert.ToDecimal(txtYears.Text),
                TypeId =Convert.ToInt32(drType.SelectedValue),
                Describe = txtDescribe.Text
            };
           //调用添加方法
            int result = MangerBLL.Add(Info);
            if (result > 0)
            {
                Response.Write("<script>alert('添加成功！');window.location.href='Default.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('添加失败！')</script>");
            }
        }
    }
}